<template>
  <div class="table-content">
    <el-table :data="tableData" border tooltip-effect="dark">
      <el-table-column
        prop="date"
        align="center"
        label="序号"
        type="index"
      ></el-table-column>
      <el-table-column
        prop="contactName"
        align="center"
        label="姓名"
        width="100px"
      ></el-table-column>
      <el-table-column
        prop="conta"
        align="center"
        label="关系"
        width="50px"
      ></el-table-column>
      <el-table-column
        prop="phone"
        align="center"
        label="号码"
        :formatter="hidInfo"
      ></el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="dangers" @click="makeCall(scope.$index,scope.row)" v-if="scope.row.pageType ==1" >
            本地拨号
          </el-button>
          <el-button size="mini" type="danger" @click="hangUpCall(scope.$index,scope.row)" v-if="scope.row.pageType ==0" >
            挂断本地
          </el-button>
          <el-button size="mini" type="dangers" @click="nomakeCall(scope.$index,scope.row)" v-if="scope.row.pagesType ==1" >
            外地拨号
          </el-button>
          <el-button size="mini" type="danger" @click="nohangUpCall(scope.$index,scope.row)" v-if="scope.row.pagesType ==0" >
            挂断外地
          </el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column v-if="isDial" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="mini"  @click="makeCall(scope.$index,scope.row)"   v-if="!ismcall"
            >本地拨号</el-button>
          <el-button type="primary" size="mini"  @click="hangUpCall(scope.$index,scope.row)"   v-if="ismcall"
            >挂断本地</el-button>
          <el-button type="primary" size="mini" @click="nomakeCall(scope.$index,scope.row)" v-if="!isycall"
          >外地拨号</el-button>
          <el-button type="primary" size="mini" @click="nohangUpCall(scope.$index,scope.row)" v-if="isycall"
          >挂断外地</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[1, 5, 10, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination> -->
  </div>
</template>

<script>
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    width: {
      type: String,
      default: "80%",
    },
    row: {
      type: Object,
      default() {
        return {};
      },
    },
    isDial: {   //操作的 v-if
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      searchData: {
        createStartTime: "",
        createEndTime: "",
        callId: "",   //通话ID
      },
      tableData: [],
      // 页码初始化数据
      total: 0, //总条目数
      tableQuery: {
        size: 10, //每页现实的条数
        page: 1, //当前显示那页
      },
      ismcall: false,
      isycall: false,
      idx: "0",
      times: {
        phoneNumber: "",
        start: "",
        end: "",
        talkBegin: "",
        talkEnd: "",
        talkTime: "",
        callFile: "1.mp3"
      }
    };
  },
  methods: {
        //页码显示条目变化
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
    },
    // 页码跳转
    handleCurrentChange(val) {
      this.tableQuery.page = val;
      this.getList();
    },
    getList() {
      let contactName = {
        size: this.tableQuery.size,
        page: this.tableQuery.page - 1,
        identificationNumber: this.row.identificationNumber,
        batchNumber: this.row.batchNumber,
        cardNumber: this.row.cardNumber,
        //putoutNo: this.row.putoutNo,
       // ...this.searchData,
      };
      // debugger
      this.$axios({
        method: "post",
        url: `/CMC/quaCont/peopleInfo`,
        data: contactName,
      }).then((res) => {
          let arr = res.data.list||[];
          for(let i=0; i< arr.length; i++){
            if(null!=arr[i]){
              let obj = arr[i];
              if(null!=obj.phone && obj.phone !=""){
                this.$set(arr[i],'pageType',1);
                this.$set(arr[i],'pagesType',1);
                this.tableData.push(arr[i]);
              }

            }

          }
        });
    },

    // 本地拨号
    makeCall(index,row){

      row.pageType =0;

      this.times.phoneNumber = row.phone;
      this.times.start = new Date().getTime();
      this.times.talkBegin = this.$moment(this.times.start).format("YYYY-MM-DD HH:mm:ss");
    },
    // 本地挂断
    hangUpCall(index,row){
      console.log("index---row:::",index,row)
      row.pageType =1;
         console.log("row.pageType>>>",row.pageType)

      this.times.end = new Date().getTime();
      this.times.talkEnd = this.$moment(this.times.end).format("YYYY-MM-DD HH:mm:ss");
      this.times.talkTime = this.$moment(this.times.end).diff(this.$moment(this.times.start),"seconds");
      this.$emit("contacted",this.times);
    },

    //外地拨号
    nomakeCall(index,row){
      console.log("index--row:::",index,row);
      row.pagesType =0;

      this.times.phoneNumber = row.phone;
      this.times.start = new Date().getTime();
      this.times.talkBegin = this.$moment(this.times.start).format("YYYY-MM-DD HH:mm:ss");
    },
    // 外地挂断
    nohangUpCall(index,row){
      console.log(index,row)
      row.pagesType =1;

      this.times.end = new Date().getTime();
      this.times.talkEnd = this.$moment(this.times.end).format("YYYY-MM-DD HH:mm:ss");
      this.times.talkTime = this.$moment(this.times.end).diff(this.$moment(this.times.start),"seconds");
      this.$emit("contacted",this.times);
    },

  },
  created() {
    this.getList();
  },
};
</script>

<style lang="scss" scoped>
.case-detail {
  padding: 10px 20px;
  background-color: #ffffff;
  border-radius: 10px;
}
::v-deep .el-tabs__active-bar {
  display: none;
}
::v-deep .el-tabs__item {
  height: auto;
}
::v-deep .el-tabs__item.is-active {
  color: #ffffff;
  background-color: #d10a14;
  padding: 0px;
  line-height: 30px;
  border-radius: 15px;
}
.el-button--dangers{
  background-color: cornflowerblue;
  border-color: cornflowerblue;
  color: #ffffff;
}
</style>
